package com.cn.lycss.servlet.product;

import com.alibaba.fastjson.JSONObject;
import com.cn.lycss.model.ProductModel;
import com.cn.lycss.model.ResultModel;
import com.cn.lycss.service.ProductService;
//import com.cn.lycss.service.impl.ProductServiceImpl;
import com.cn.lycss.service.impl.ProductServiceImpl;
import com.cn.lycss.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/product/findAll")
public class ProductFindAllServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        1乱码
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //      1.取得页面的值
        String page = req.getParameter("page");
        String limit = req.getParameter("limit");
        //      2.封装数据
        ProductModel model = new ProductModel();
        model.setPageNumber(Tool.aa(page));
        model.setPageSize(Tool.aa(limit));
        //      3.调用逻辑层
        ProductService productService = new ProductServiceImpl();
//      4.得到返回结果
        ResultModel resultModel = productService.findAll(model);
//      5.返回结果集
        resp.getWriter().println(JSONObject.toJSONString(resultModel));
    }
}
